﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;

namespace FanaticRock.Theme.Custom.Primitives
{      
    // 仅水平布局，主要是解决WPF默认的样式 Thumb 并没有连在一起。
    public class TrackEx:Track
    {
        protected override Size ArrangeOverride(Size arrangeSize)
        {
            if(Maximum == Minimum) return arrangeSize;

            base.ArrangeOverride(arrangeSize);

            var left = DecreaseRepeatButton;
            var right = IncreaseRepeatButton;

            var leftRatio = (Value - Minimum) / (Maximum - Minimum);
            var rightRatio = 1 - leftRatio;

            var leftWidth = leftRatio * arrangeSize.Width;
            var rightWidth = rightRatio * arrangeSize.Width;

            left.Width = leftWidth;
            right.Width = rightWidth;

            //left.Height = arrangeSize.Height;
            //right.Height = arrangeSize.Height;

            var thumb = Thumb;
            var cx = leftWidth;
            var cy = arrangeSize.Height / 2;
            var th = thumb.Height;
            var tw = thumb.Width;

            var tx = cx - tw / 2;
            var ty = cy - th / 2;

            thumb.Arrange(new Rect(tx, ty, tw, th));
            left.Arrange(new Rect(0, cy - left.Height / 2, leftWidth, left.Height));
            right.Arrange(new Rect(leftWidth, cy - right.Height / 2, rightWidth, right.Height));

            return arrangeSize;
        }

    }
}
